/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2021-09-17
 * Time:20:08
 */
public class TestDemo {
    //StringBuffer 和 StringBuilder 是可变的 每次拼接都返回的是当前的对象
    //synchronized 是来保证线程安全
    //StringBuffer 适合多线程
    //StringBuilder 适合单线程

    //String 与 StringBuffer、StringBuilder 不可以直接转换

    // String 只能通过构造方法 和 qppend来转换为StringBuffer、StringBuilder
    // StringBuffer、StringBuilder  通过 toString()方法转换为 String
    public static void main(String[] args) {
        String str = "hello";
        for (int i = 0; i < 10; i++) {
            StringBuilder sb = new StringBuilder();
            str = sb.append(str).append(i).toString();
        }
        System.out.println(str);
    }
    public static void main1(String[] args) {
        String str = "hello";
        StringBuilder sb = new StringBuilder();
        sb.append(str);
        for (int i = 0; i < 10; i++) {
            sb.append(i);
        }
        str = sb.toString();
        System.out.println(str);
    }
}
